package com.itheima.tlias84.mapper;

import com.itheima.tlias84.dto.ReportEmpGenderDTO;
import com.itheima.tlias84.dto.SelectAllEmpDTO;
import com.itheima.tlias84.dto.SelectEMPDetailDTO;
import com.itheima.tlias84.dto.SelectEmpDTO;
import com.itheima.tlias84.entity.Emp;
import com.itheima.tlias84.po.InsterEmpParam;
import com.itheima.tlias84.po.SelectEmpPageParam;
import com.itheima.tlias84.po.UpdateEmpParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 都是标识Dao层的注解
 * @Mapper ->mybatis 提供
 * @Repository ->由spring 提供
 */
@Mapper
//@Repository
public interface EmpMapper {
    //查询所有
   List<SelectAllEmpDTO> selectAll();
    //分页查询
    List<SelectEmpDTO> selectEmpByPage(@Param("p")SelectEmpPageParam param);
    //批量删除
    int batchDelete(@Param("ids") List<Integer> ids);
    //插入
    int insertEmp(@Param("p") InsterEmpParam param);

    int updateEmp(@Param("p") UpdateEmpParam param);

    SelectEMPDetailDTO selectEmpById(@Param("id") Integer id);

    //用户登录
    @Select("select id,username,password,name from emp where username=#{username}")
    Emp selectEmpByUsername(@Param("username") String username);

    @Select("select count(gender) as value,case gender when 1 then'男性' when 2 then'女性' end as name from emp" +
            " group by gender")
    List<ReportEmpGenderDTO> countEmpByGender();

    @Select("select job from emp")
    List<Integer> countEmpByJob();
}
